//
//  SettingTableViewCell.m
//  Project_B
//
//  Created by 甘霞 on 15/11/27.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "SettingTableViewCell.h"
#import "Masonry.h"

@interface SettingTableViewCell ()

@property (nonatomic, retain) UIImageView *myImageView;

@property (nonatomic, retain) UILabel *label;

@property (nonatomic, retain) UISwitch *settingSwitch;

@end

@implementation SettingTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    
    self.myImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.myImageView];
    
    self.label = [[UILabel alloc] init];
    [self.label setTextColor:[UIColor whiteColor]];
    [self.label setTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:self.label];
    
    self.settingSwitch = [[UISwitch alloc] init];
    [self.contentView addSubview:self.settingSwitch];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [self.settingSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(self.label.mas_right).with.offset(5);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);

    }];
    
    [self.myImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.height, self.contentView.frame.size.height));
        make.top.equalTo(self.contentView);
    }];
    
    self.myImageView.layer.cornerRadius = self.contentView.frame.size.height / 2;
    self.myImageView.layer.masksToBounds = YES;
    
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.myImageView.mas_right).offset(10);
        make.height.equalTo(self.contentView.mas_height);
        make.top.equalTo(self.contentView);
        make.width.mas_equalTo(@100);
    }];
}

- (void)setDic:(NSDictionary *)dic {
    if (_dic != dic) {
        _dic = dic;
    }
    
    self.imageView.image = [UIImage imageNamed:dic[@"image"]];
    self.label.text = dic[@"text"];
    self.settingSwitch.hidden = [dic[@"switch"] boolValue];
}

@end
